package com.swufe.week6;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity2 extends AppCompatActivity {

    String TAG ;
    EditText dollarEditor;
    EditText euroEditor;
    EditText wonEditor;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        //接收数据
        Intent conf=getIntent();
        float dollar=conf.getFloatExtra("dollar_rate_key",0.0f);
        float euro=conf.getFloatExtra("euro_rate_key",0.0f);
        float won=conf.getFloatExtra("won_rate_key",0.0f);

        Log.i(TAG, "onCreate: dollar="+dollar);
        Log.i(TAG, "onCreate: euro="+euro);
        Log.i(TAG, "onCreate: won="+won);
        //获取控件

        dollarEditor = findViewById(R.id.edit_dollar);
        euroEditor = findViewById(R.id.edit_euro);
        wonEditor = findViewById(R.id.edit_won);

        //将汇率值放入控件
        dollarEditor.setText(String.valueOf(dollar));
        euroEditor.setText(String.valueOf(euro));
        wonEditor.setText(String.valueOf(won));
    }
    public void save(View btn){
        float newDollar=Float.parseFloat(dollarEditor.getText().toString());
        float newEuro=Float.parseFloat(euroEditor.getText().toString());
        float newWon=Float.parseFloat(wonEditor.getText().toString());
        Intent intent=getIntent();
        Bundle bdl =new Bundle();
        bdl.putFloat("key_dollar",newDollar);
        bdl.putFloat("key_euro",newEuro);
        bdl.putFloat("key_won",newWon);
        intent.putExtras(bdl);
        setResult(2,intent);
        finish();



    }
}
